package lab02.test24;
import java.text.ParseException;
import  java.text.SimpleDateFormat;
import java.util.*;
public class Test24 {
    public static void main(String[] args) throws ParseException {
         System.out.println("请输入第一个日期：");
         Scanner sc = new Scanner(System.in);
         String time1 = sc.nextLine();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");//将输入的字符串格式化
         Date t1 = (Date) sdf.parse(time1);//解析字符串为时间
         String  da1 = String.format("%tY年%tm月%td日",t1,t1,t1);//注意年月日的大小写
        System.out.println(da1);

        Calendar c = Calendar.getInstance();//用来获得实例
        c.setTime(t1);//创建一个指定的calendar的对象
        long a = c.getTimeInMillis();

         System.out.println("请输入第二个日期：");
         String time2 = sc.nextLine();
         java.util.Date t2 =sdf.parse(time2);
         String  da2 = String.format("%tY年%tm月%td日",t2,t2,t2);
         System.out.println(da2);

        c.setTime(t2);
        long b = c.getTimeInMillis();

        long between_days = (b-a)/(1000*3600*24);//将微妙转化为天数
        System.out.println("两个日期相差天数:"+between_days+"天");


    }

}
